package com.util;

import javax.sql.DataSource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 
 *
 *@类名称：DataSourceBeanUtil.java
 *@类描述：dataSource单例获取util
 *@创建人：zhongy
 *@创建时间：2017年5月4日-下午10:26:00
 *@修改备注:
 *@version
 */
public class DataSourceBeanUtil implements ApplicationContextAware {
	private static ApplicationContext context;
	private static DataSource dataSource;

	public void setApplicationContext(ApplicationContext contex) throws BeansException {
		DataSourceBeanUtil.context = contex;
	}

	public static ApplicationContext getContext() {
		return context;
	}
	

	public static DataSource getDataSource() {
		if(dataSource!=null)
			return dataSource;
		dataSource = (DataSource)getContext().getBean("dataSource");
		return dataSource;
	}
}
